<template>
  <el-menu active-text-color="#409eff" background-color="#304156" class="el-menu-vertical-demo"
    :default-active="activeIndex" text-color="#fff" @open="handleOpen" @close="handleClose" unique-opened router>
    <el-menu-item index="/index">
      <i class="iconfont homepage"></i>
      <span>首页</span>
    </el-menu-item>
    <el-sub-menu :index="`/${p.name}`" v-for="p in userStore.activeMenus" :key="p.id">
      <template #title>
        <i class="iconfont" :class="p.icon"></i>
        <span>{{ p.title }}</span>
      </template>
      <el-menu-item :index="`/${p.name}/${sub.name}`" v-for="sub in p.children">
        <i class="iconfont" :class="sub.icon"></i>
        <span>{{ sub.title }}</span>
      </el-menu-item>
    </el-sub-menu>
  </el-menu>
</template>

<script setup lang="ts">
import { useUserStore } from "@/store";
import { ref, watch } from "vue";
import { useRoute } from "vue-router";

const userStore = useUserStore();
const handleOpen = (key: string, keyPath: string[]) => {
  // console.log(key, keyPath);
};
const handleClose = (key: string, keyPath: string[]) => {
  // console.log(key, keyPath);
};

const route = useRoute()
let activeIndex = ref(route.path)
watch(
  () => route.path, () => {
    activeIndex.value = route.path
  })

</script>

<style scoped>
.el-menu {
  border: none;
}
</style>
